<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/10/24
 * Time: 15:53
 */
class AhpMaintenanceShops extends Eloquent
{
    protected $table = "ahp_maintenance_shops";

    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 上午11:13
     * @Description: 获取门店所在城市信息
     * @param
     * @return []
     */
    public function cityinfo()
    {
        return $this->hasOne('ResourceCityType',"id","city_id");
    }

    /**
     * @Author:      sqq
     * @DateTime:    2018-11-14 11:14:20
     * @Description: 门店详情
     * @Param: $shop_id 门店id
     * @Return: Object
     */
    public static function getDetails($shop_id){
        return AhpMaintenanceShops::where('cms_shop_id',$shop_id)
            ->where('status',1)
            ->where('cms_status',1)
            ->select([
                'cms_shop_id as id',
                'cms_shop_name as name',
                'address',
                'longitude',
                'latitude',
                'tel_phone',
                'thumbnail as small_image',
                'show_image as image',
                'business_start_time',
                'business_end_time',
                'desc',
            ])
            ->first();
    }

    /**
     * @Author:      sqq
     * @DateTime:    2018-08-17 09:43:29
     * @Description: 门店列表
     * @Param: $city_id 城市id
     * @Param: $region_id 区县id
     * @Return: Object
     */
    public static function getShopWechat3($city_id, $region_id){
        $shops = new AhpMaintenanceShops();
        if($city_id){
            $shops = $shops->where('city_id',$city_id);
        }
        if($region_id){
            $shops = $shops->where('region_id',$region_id);
        }
        $shops = $shops->where('status',1)
            ->where('cms_status',1)
            ->select([
                'cms_shop_id as id',
                'cms_shop_name as name',
                'address',
                'longitude',
                'latitude',
                'tel_phone',
                'thumbnail as small_image',
                'show_image as image',
                'business_start_time',
                'business_end_time',
                'desc',
            ])
            ->get();
        return $shops;
    }
}